<template>
	<app-layout>
		<app-banner></app-banner>
		<app-title text="推荐藏品" :width="64"></app-title>
		<view class="topic-page">
			<view class="topic-list">
				<view class="list-item" v-for="item in listData" :key="item.id">
					<view class="topic-img" @click="$tool.navigateTo(`/pages/topic/list?id=${item.id}`)">
						<view class="status">{{item.topicStatusName}}</view>
						<image class="image" :src="item.pictureUrl" mode=""></image>
					</view>
					<view class="topic-info" @click="$tool.navigateTo(`/pages/topic/list?id=${item.id}`)">
						<text>{{item.topicName}}</text>
						<text>{{item.sysUserName}}</text>
					</view>
				</view>
			</view>
			<uni-load-more :contentText="contentText" @clickLoadMore="onClickLoadMore" :status="queryStatus">
			</uni-load-more>
		</view>
	</app-layout>
</template>

<script>
	import {
		getTopicPage
	} from '../../request/topic-api.js'
	export default {
		data() {
			return {
				// 主题数组
				listData: [],
				// 列表查询参数
				params: {
					condition: "",
					pageNum: 0,
					pageSize: 6
				},
				// 没有更多了
				isNoMore: false,
				// 加载状态
				queryStatus: 'more',
				// 各状态文字说明
				contentText: {
					contentdown: "点击加载更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				}
			}
		},
		created() {
			this.onLoadListData()
		},
		methods: {
			// 点击加载更多
			onClickLoadMore() {
				if (!this.isNoMore) {
					this.onLoadListData()
				}
			},

			// 加载 数据
			async onLoadListData() {
				this.queryStatus = 'loading'
				this.params.pageNum += 1
				try {
					let {
						code,
						message,
						data
					} = await getTopicPage(this.params)
					if (code === 200) {
						if (this.params.pageNum <= data.totalPage) {
							this.isNoMore = false
							this.listData.push(...data.list)
							this.queryStatus = 'more'
						} else {
							this.isNoMore = true
							this.queryStatus = 'noMore'
						}
					} else {
						this.queryStatus = 'more'
						uni.showToast({
							title: message,
							icon: 'error'
						})
					}
				} catch (err) {
					this.queryStatus = 'more'
					this.$tool.showErr(err)
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.topic-page {
		width: 100%;
		min-height: 100vh;

		.topic-list {
			width: 100%;
			margin: 30rpx 0;

			.list-item {
				width: 100%;
				height: 430rpx;
				margin-bottom: 40rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				.topic-img {
					width: 100%;
					min-height: 350rpx;
					border-radius: 30rpx;
					position: relative;

					.status {
						width: 160rpx;
						height: 60rpx;
						background: $common-prod-status no-repeat;
						background-size: 100% 100%;
						background-position: 0 0;
						position: absolute;
						top: 0;
						left: 0;
						z-index: 1;
						font-size: 18px;
						font-family: YouSheBiaoTiHei;
						color: #222124;
						font-weight: bold;
						line-height: 60rpx;
						text-align: center;
					}

					.image {
						width: 100%;
						height: 100%;
						border-radius: 30rpx;
					}
				}

				.topic-info {
					width: calc(100% - 80rpx);
					height: 80rpx;
					padding: 0 30rpx;
					background: linear-gradient(172deg, #191919 0%, #535353 100%);
					border-radius: 0 0 14px 14px;
					display: flex;
					align-items: center;
					justify-content: space-between;

					text {
						font-size: 14px;
						font-family: PingFangSC-Semibold, PingFang SC;
						font-weight: 600;
						color: #EEFDFE;
					}
				}
			}

		}
	}
</style>
